﻿using System;
using System.Windows.Forms;
using Studentium.Entities;

namespace Studentium.UIElements
{
    public partial class EditComment : Form
    {
        private readonly StudentInfoTabs studentInfos;
        private readonly bool newComment;
        private readonly Comment comment;

        public EditComment(Comment comment, StudentInfoTabs studentInfos, bool newComment)
        {
            InitializeComponent();

            this.comment = comment;
            this.studentInfos = studentInfos;
            this.newComment = newComment;            

            typeBox.DataSource = Enum.GetValues(typeof(CommentType));
            typeBox.SelectedItem = comment.CommentType;
            authorBox.Text = comment.Author;
            textBox.Text = comment.Text;
        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            comment.Text = textBox.Text;
            comment.CommentType = (CommentType)typeBox.SelectedItem;
            comment.Author = authorBox.Text;

            if (newComment)
            {
                comment.Date = DateTime.Now;
                studentInfos.SaveNewStudentItem(comment);
            }
            else
                studentInfos.UpdateStudentItem(comment);

            this.Close();
        }
    }
}
